package com.xinxing.city.recovery.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.xinxing.city.recovery.R;
import com.xinxing.city.recovery.databinding.ActivitySetHeartBinding;
import com.xinxing.city.recovery.entitys.SetCategory;
import com.xinxing.city.recovery.entitys.SetHeart;
import com.xinxing.city.recovery.utils.SharedPreferencesUtils;

import java.lang.reflect.Type;

public class SetHeartActivity extends AppCompatActivity {
    private ActivitySetHeartBinding binding;
    private SetHeart heart = new SetHeart();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_set_heart);
        init();
        binding.setSetHeart(heart);
    }
    private void init(){
        String str = (String) SharedPreferencesUtils.getParam(this,"set_heart","");
        if(!str.equals("")){
            Type dev = new TypeToken<SetHeart>() {}.getType();
            Gson gson = new Gson();;
            heart = gson.fromJson(str,dev);
        }
    }
    public void saveSub(View view){
        Gson gson = new Gson();;
        SharedPreferencesUtils.setParam(this,"set_heart",gson.toJson(heart));
        Toast.makeText(this,"保存成功",Toast.LENGTH_SHORT).show();
        this.finish();
    }
}
